package com.erge.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.erge.common.annotation.Log;
import com.erge.common.core.controller.BaseController;
import com.erge.common.core.domain.AjaxResult;
import com.erge.common.enums.BusinessType;
import com.erge.student.domain.StudentDO;
import com.erge.student.service.IStudentService;
import com.erge.common.utils.poi.ExcelUtil;
import com.erge.common.core.page.TableDataInfo;

import lombok.RequiredArgsConstructor;

/**
 * 学生Controller
 *
 * @author roydon
 * @date 2025-05-22
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/student/student")
public class StudentController extends BaseController {
    private final IStudentService studentService;

    /**
     * 查询学生列表
     */
    @PreAuthorize("@ss.hasPermi('student:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentDO student) {
        startPage();
        List<StudentDO> list = studentService.selectStudentList(student);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @PreAuthorize("@ss.hasPermi('student:student:export')")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentDO student) {
        List<StudentDO> list = studentService.selectStudentList(student);
        ExcelUtil<StudentDO> util = new ExcelUtil<StudentDO>(StudentDO.class);
        util.exportExcel(response, list, "学生数据");
    }

    /**
     * 获取学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('student:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(studentService.selectStudentById(id));
    }

    /**
     * 新增学生
     */
    @PreAuthorize("@ss.hasPermi('student:student:add')")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentDO student) {
        return toAjax(studentService.insertStudent(student));
    }

    /**
     * 修改学生
     */
    @PreAuthorize("@ss.hasPermi('student:student:edit')")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentDO student) {
        return toAjax(studentService.updateStudent(student));
    }

    /**
     * 删除学生
     */
    @PreAuthorize("@ss.hasPermi('student:student:remove')")
    @Log(title = "学生", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(studentService.deleteStudentByIds(ids));
    }

    //    统计图表======
    @GetMapping("/chart/count")
    public AjaxResult countChart() {
        return success(studentService.countChart());
    }

    /**
     * 院系报道情况
     */
    @GetMapping("/chart/report")
    public AjaxResult reportChart() {
        return success(studentService.reportChart());
    }

    /**
     * 性别比例
     */
    @GetMapping("/chart/gender")
    public AjaxResult genderChart() {
        return success(studentService.genderChart());
    }



}
